<?php

$app->get('/locations', 'findLocations');

function findLocations() {
	$app = \Slim\Slim::getInstance();
	$latitude = floatval($app->request()->get('latitude'));
	$longitude = floatval($app->request()->get('longitude'));
	$distance = floatval($app->request()->get('distance'));

	if (!$latitude || !$longitude) 
		errorOut("INVALID_ARGUMENT", "Latitude and longitude must be defined!");
	if ($distance <= 0)
		$distance = CONST_DISTANCE;
			
	$sqlQuery = createLocationSelectWithDistance($latitude, $longitude, " HAVING distance < $distance");
	jsonOut(doGetListResult($sqlQuery));
}

?>